package org.stu.tp.core;

import java.io.*;
import java.util.*;
import com.thoughtworks.selenium.SeleneseTestCase;

public class DefaultTestCase extends SeleneseTestCase {
	static Properties props = new Properties();
	private String host;
	private int port;
	private String browser;
	private String url;
	protected DefaultAjaxSelenium selenium;
	static {
		try {
			InputStream in = new BufferedInputStream(new FileInputStream(
					"test.properties"));
			props.load(in);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.thoughtworks.selenium.SeleneseTestCase#setUp()
	 */
	public void setUp() throws Exception {
		this.host = props.getProperty("host");
		this.port = Integer.parseInt(props.getProperty("port"));
		this.browser = props.getProperty("browser");
		this.url = props.getProperty("url");
		selenium = new DefaultAjaxSelenium(host, port, browser, url);
		
		selenium.start();
		selenium.setContext(this.getClass().getSimpleName() + "." + getName());
		selenium.useXpathLibrary("javascript-xpath");
		selenium.windowMaximize();
	}

	public void tearDown() throws Exception {
		selenium.stop();
	}
	
	public DefaultAjaxSelenium getSelenium() {
		return selenium;
	}

	public void restartSelenium()throws Exception{
		this.selenium.stop();
		setUp();
	}
	
}
